package com.xxx.mch.event.handler;

import com.alibaba.fastjson.JSON;
import com.xxx.mch.domain.po.TotalScore;
import com.xxx.mch.service.TotalScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * @author FengHaixin
 * @description 一句话描述该文件的用途
 * @date 2020/3/3
 */
@Slf4j
@Component
public class TotalScoreChangeHandler
{

    @Autowired
    private TotalScoreService totalScoreService;


    @TransactionalEventListener (phase = TransactionPhase.BEFORE_COMMIT, fallbackExecution = true, value = TotalScore.class)
    public void scoreChange(TotalScore totalScore)
    {
        log.info("收到评分变更事件：{}", JSON.toJSONString(totalScore));
        totalScoreService.calculateTotalScore(totalScore);
    }
}
